<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('项目报备新增及修改')" />
	<th:block th:include="include :: businessCSS" />
</head>
<body class="no-skin">
<div class="main-container" id="main-container">
	<div class="main-content">
	<form class="layui-form head-form">
	    <div class="north">
            <th:block th:include="include :: business_btn" />
	        <th:block th:include="include :: business_tpl('top')" />
			<blockquote class="layui-elem-quote"><b>项目金额及费用</b></blockquote>
			<div class="layui-form layui-card-header layuiadmin-card-header-auto" style="width:calc(100%-30px)">
				<div class="layui-form-item margin_t0">
					<div th:class="'layui-inline margin_r0 '+${field.fieldFrontTopSize eq 1 ?'layui-col-sm4':(field.fieldFrontTopSize eq 2 ?'layui-col-sm8':'layui-col-sm12')}" th:each="field : ${fieldsStaticList}">
		               	<label class="layui-form-label">
	                		<font class="f_red" th:if="${#bools.isTrue(field?.fieldFrontRequired)}">*</font>[[${field.fieldName}]]：
		              	</label>
		               	<div class="layui-input-block" th:unless="${gridColumns.readOnly}">
		                    <input th:if="${field.fieldFrontType} eq 't_text'" type="text" th:name="${field?.fields}" th:id="${field?.fields}" th:value="${field?.fieldContent}"  th:class="${field?.fieldFrontEdit}?'layui-input':'layui-input canntEdit'" autocomplete="off" 
		                    		th:onblur="${field?.fieldFrontRequired}?'inputOnBlur(this)':''" th:readonly="${field?.fieldFrontEdit}?'false':'true'">
		                    <input th:if="${field.fieldFrontType} eq 't_decimal'" type="number" th:name="${field?.fields}" th:id="${field?.fields}" th:value="${field?.fieldContent}" th:class="${field?.fieldFrontEdit}?'layui-input':'layui-input canntEdit'" autocomplete="off" lay-verify="number"
		                    		th:onblur="${field?.fieldFrontRequired}?'inputOnBlur(this)':''" th:readonly="${field?.fieldFrontEdit}?'false':'true'">
		                    <input th:if="${field.fieldFrontType} eq 't_date' or ${field.fieldFrontType} eq 't_datetime'" type="text" th:name="${field?.fields}" th:id="${field?.fields}" th:value="${field?.fieldContent}" autocomplete="off" th:class="${field.fields} ne 'createTime' and ${field?.fieldFrontEdit}?'layui-input t_date':'layui-input t_date canntEdit'" th:onblur="${field?.fieldFrontRequired}?'inputOnBlur(this)':''">
                    			<i th:if="(${field.fieldFrontType} eq 't_date' or ${field.fieldFrontType} eq 't_datetime') and ${field.fields} ne 'createTime' and ${field?.fieldFrontEdit}"  th:id="${field?.fields} + '_date'" class="dhicon dh-calendar icon_date_business" style="font-size:0"></i>
					    	<input th:if="${field.fieldFrontType} eq 't_checkbox'" type="checkbox" th:checked="${field?.fieldContent == false or field?.fieldContent == null}" value="0" th:name="${field?.fields}" th:id="${field?.fields}" lay-skin="switch" th:lay-text="${field?.fields == 'bDeleted'} ? '启用|禁用' : '是|否'" th:disabled="${gridColumns.readOnly}">
						  	<input th:if="${field.fieldFrontType} eq 't_buttontext'" type="text" th:class="${field.fieldFrontEdit}?'layui-input buttontext':'layui-input canntEdit'" th:name="${field?.fields}" th:id="${field?.fields}" th:value="${field?.fieldContent}" readonly/>
						  		<i th:if="${field.fieldFrontType} eq 't_buttontext' and ${field.fieldFrontEdit}" class="layui-icon layui-icon-more getMore" th:onclick="getMore([[${field?.fields}]],null,[[${field?.fieldName}]],[[${field?.fieldSearchType}]]);" th:getType="${field?.fields}"></i>
							<select th:if="${field.fieldFrontType} eq 't_dropdown'" type="text" th:id="${field?.fields}" th:name="${field?.fields}" autocomplete="off" class="layui-select" lay-search th:with="map=${field?.dropdownList}" lay-filter="select_top" th:data-fieldMatched="${field?.fieldMatched}" th:data-fieldFrontSave="${field?.fieldFrontSave}" th:data-fieldFrontShow="${field?.fieldFrontShow}">
								<option></option>
								<option th:each="dict : ${map}" th:text="${dict.vname}" th:value="${dict.vid}" th:selected="(${#strings.isEmpty(field.fieldContent)} and ${dict.bdefaulttext eq '是'}) or ${dict.vid.toString() eq field.fieldContent.toString()} or ${dict.vname.toString() eq field.fieldContent.toString()}" th:data-vremark="${dict.vremark}"></option>
							</select>
							<input th:if="${field.fieldFrontType} eq 't_dropdownedit'" type="text" th:name="${field?.fields}" th:id="${field?.fields}" th:value="${field?.fieldContent}" class="layui-input" style="position:absolute;overflow:hidden;z-index:2;width: calc(100% - 30px);" lay-verify="required" onkeyup="inputSearch()" onblur="refreshSelect()" autocomplete="off">
			               	<select th:if="${field.fieldFrontType} eq 't_dropdownedit'" th:id="${field?.fields}+'_select'" th:lay-filter="${field?.fields}+'_select'" autocomplete="off" class="layui-select" lay-search th:with="map=${field?.dropdownList}">
								<option th:each="dict : ${map}" th:text="${dict.vname}" th:value="${dict.vid}" th:selected="(${#strings.isEmpty(field.fieldContent)} and ${dict.bdefaulttext eq '是'}) or ${dict.vid.toString() eq field.fieldContent.toString()} or ${dict.vname.toString() eq field.fieldContent.toString()}"></option>
							</select>
							<input th:if="${field.fieldFrontType} eq 't_file'" type="text" class="layui-input buttontext" th:name="${field?.fields}" th:id="${field?.fields}" th:value="${field?.fieldContent}" readonly/><i th:if="${field.fieldFrontType} eq 't_file'" class="layui-icon layui-icon-upload getUpload" th:onclick="getUpload([[${field?.fields}]]);" th:getType="${field?.fields}"></i>
							<textarea th:if="${field.fieldFrontType} eq 't_textarea'" th:name="${field?.fields}" th:id="${field?.fields}" th:value="${field?.fieldContent}" th:class="${field?.fieldFrontEdit}?'layui-textarea':'layui-textarea canntEdit'" th:readonly="${field?.fieldFrontEdit}?'false':'true'">[[${field.fieldContent}]]</textarea>
						</div>
						<div class="layui-input-block" th:if="${gridColumns.readOnly}" th:switch="${field.fieldFrontType}">
							<textarea th:case="t_textarea" th:name="${field?.fields}" th:id="${field?.fields}" th:value="${field?.fieldContent}" class="layui-textarea canntEdit" readonly>[[${field.fieldContent}]]</textarea>
							<input th:case="t_file" type="text" class="layui-input buttontext" th:name="${field?.fields}" th:id="${field?.fields}" th:value="${field?.fieldContent}" readonly/><i th:if="${field.fieldFrontType} eq 't_file'" class="layui-icon layui-icon-upload getUpload" th:onclick="getUpload([[${field?.fields}]]);" th:getType="${field?.fields}"></i>
							<input th:case="t_checkbox" type="checkbox" th:checked="${field?.fieldContent == false or field?.fieldContent == null}" value="0" th:name="${field?.fields}" th:id="${field?.fields}" lay-skin="switch" th:lay-text="${field?.fields == 'bDeleted'} ? '启用|禁用' : '是|否'" disabled>
							<input th:case="*" type="text" th:name="${field?.fields}" th:id="${field?.fields}" th:value="${field?.fieldContent}"  class="layui-input canntEdit" autocomplete="off" readonly>
						</div>
		            </div>
				</div>
			</div>
    	</div>
	    <th:block th:include="include :: pageFooter" /> 
        </form>
	</div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: businessJS" />
<th:block th:include="include :: inlineJS" />
<script type="text/javascript">
var $,layer,form,laydate,element,companyList;//定义layui模块
var nid = $("#nid").val(),noTable;//定义全局参数
layui.use(['laydate','form','layer','jquery','util','element'], function () {
 	$ = layui.$,layer = layui.layer,form = layui.form,laydate = layui.laydate,util = layui.util,element=layui.element;
 	beforeInit();//表单初始化之前的动作集合
 	layui.element.render();
 	$.get("/business/projectadded/listbynid?nid="+nid,function(res){
 		noTable=res.data;
	});
 	$.get("/base/company/list?effectStock=1",function(res){//获取公司列表
 		companyList=res.data;
	});
 	form.on('select()', function (obj) {//监听下拉框
		if(obj.elem.name=='vXmLx'){
			$.each(companyList,function(i,v){
				if(v.vId == $('#cid').val()){
					var bidArr = $('#bid').val().split('-');
					bidArr[0] = v.vSign;
					bidArr.push(obj.value);
					$('#vXmBm').val(bidArr.join('-'));
				}
			})
		}
	});
 	//遍历静态网格字段，时间控件渲染
	$.each(t_fields,function(k,v){
		if((v.fieldFrontType=="t_date" || v.fieldFrontType=="t_datetime" || v.fieldFrontType=="t_year") && v.fieldFrontEdit && !gridColumns.readOnly){//表头时间控件渲染（非只读）
			$('#'+v.fields).unbind();//清除事件，防止重复监听
			$('#'+v.fields).on('change',function(){//手动修改日期
				var errorMsg = '';//错误提示
				switch(v.fieldFrontType){
					case 't_date':
						if(judgeStrDate($('#'+v.fields).val())){//验证日期格式
							var r = $('#'+v.fields).val().match(/^(\d{1,4})(-|\/|.)(\d{1,2})\2(\d{1,2})$/);
							if(typeof judgeTopDate == 'function'){
								judgeTopDate('#'+v.fields,formatDate(new Date(r[1], r[3]-1, r[4]),'date'));
							}else $('#'+v.fields).val(formatDate(new Date(r[1], r[3]-1, r[4]),'date'));
						}else errorMsg = '请输入正确时间格式，形如2020-01-01';
						break;
					case't_datetime':
						if(judgeStrDateTime($('#'+v.fields).val())){//验证日期时间格式
							var r = $('#'+v.fields).val().match(/^(\d{1,4})(-|\/|.)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/);
							if(typeof judgeTopDate == 'function'){
								judgeTopDate('#'+v.fields,formatDate(new Date(r[1], r[3]-1, r[4], r[5], r[6], r[7])));
							}else $('#'+v.fields).val(formatDate(new Date(r[1], r[3]-1, r[4], r[5], r[6], r[7])));
						}else errorMsg = '请输入正确时间格式，形如2020-01-01 00:00:00'; 
						break;
					case 't_year':
						if(judgeStrYear($('#'+v.fields).val())){//验证年份格式
							var r = $('#'+v.fields).val().match(/^(\d{1,4})$/);
							if(typeof judgeTopDate == 'function'){
								judgeTopDate('#'+v.fields,formatDate(new Date(r[1]),'year'));
							}else $('#'+v.fields).val(formatDate(new Date(r[1]),'year'));
						}else errorMsg = '请输入正确时间格式，形如2020';
						break;
				}
				if(errorMsg){//如果存在错误提示，则清空控件内容并提示错误
					$('#'+v.fields).val('');
					layer.msg(errorMsg);
				}
			})
			laydate.render({
				elem:'#'+v.fields+'_date',
				type:v.fieldFrontType.substring(2,v.fieldFrontType.length),
				trigger:'click',
				done:function(value, date){
					$('#'+v.fields).val(value);//原输入控件赋值
				}
			});
		}
	});
})
function getMoreAfter(fieldsList){//弹出框赋值回调
	if(fieldsList['cid'] && $('#vXmBm').val()){//所属公司、项目编码
		var xmbmArr = $('#vXmBm').val().split('-');
		$.each(companyList,function(i,v){
			if(v.vId == $('#cid').val()){
				xmbmArr[0] = v.vSign;
				$('#vXmBm').val(xmbmArr.join('-'));
			}
		})
	}
}
</script>
</body>
</html>